package com.linshen.grpcspringcloudprovider;

import com.linshen.grpc.cloud.lib.HelloWorldGrpc;
import com.linshen.grpc.cloud.lib.Helloworld;

import io.grpc.stub.StreamObserver;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.server.service.GrpcService;

/**
 * GRPC HelloWorld服务
 *
 * @author chenw
 * @date 2020/12/16
 */
@GrpcService
@Slf4j
public class HelloWorldService extends HelloWorldGrpc.HelloWorldImplBase {
    @Override
    public void sayHello(Helloworld.HelloWorldRequest request,
        StreamObserver<Helloworld.HelloWorldReply> responseObserver) {

        String message = "Hi " + request.getName();
        final Helloworld.HelloWorldReply.Builder replyBuilder = Helloworld.HelloWorldReply.newBuilder().setMessage(message);
        responseObserver.onNext(replyBuilder.build());
        responseObserver.onCompleted();
        log.info("返回消息 " + message);
    }
}
